#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

int n;
string a;

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);


    int T;
    cin >> T;
    while(T--){
        cin >> n;
        cin >> a;
        
        if(a[0] != '9'){
            // cout << a << endl;
            string res(n, '9');
            int ed1 = n - 1, ed2 = n - 1;
            for(int i = 0; i < n; i ++){
                res[i] = char('0' + res[i] - a[i]);
            }
            
            cout << res << endl;

        }else{
            string b(n + 1, 'a');
            
            b[0] = b[n] = '1';
            for(int i = 1; i < n; i ++){
                b[i] = '4';
            }
            
            // cout << "b: " << b << " a:" << a << endl;

            //a [0, n - 1] b[0, n]
            int ed1 = n - 1, ed2 = n;
            int k = 0;
            for(int i = 0; i < n; i ++){
                int dis = b[ed2 - i] - a[ed1 - i];
                dis -= k;
                // cout << "dis: " << dis << endl;
                k = 0;
                if(dis >= 0){
                    a[ed1 - i] = char('0' + dis);
                }else{
                    //dis < 0;
                    k = 1;
                    a[ed1 - i] = char('0' + dis + 10);
                }
            }

            cout << a << endl;
        }
    }


    return 0;
}